package com.opesoft.fw.i18n.taglib;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.Tag;

public class Set extends Base
{
	protected String name;
	protected String id;
	protected String[] ids=new String[]{"one","two"};

	public String[] getIds()
	{
		return ids;
	}

	public void setIds(String[] ids)
	{
		this.ids=ids;
	}

	public int doEndTag() throws JspException
	{
		if(name!=null)
		{
			if(id==null) id=name; // 默认Id和Name一至
			pageContext.setAttribute(id,this.findI18nMessage(this.name));
		}
		else
		{
			String str=this.getBodyContent().getString();
			if(str!=null&&str.length()>0)
			{
				String[] items=str.split("\n");
				for(int i=0;i<items.length;i++)
				{
					String item=items[i].trim();
					
					if(item.length()>0)
					{
						String k,v;
						int place=item.indexOf("=");
						
						if(place>-1)
						{
							k=item.substring(0,place);
							v=item.substring(place+1);
						}
						else
						{
							k=item;
							v=item;
						}

						pageContext.setAttribute(k,this.findI18nMessage(v));
					}

				}
			}
		}

		name=null;
		id=null;
		return Tag.EVAL_PAGE;
	}

	public String getId()
	{
		return id;
	}

	public void setId(String id)
	{
		this.id=id;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name=name;
	}
}
